package day240527.work;



import java.util.TreeSet;

public class TreeSetDemo {
    public static void main(String[] args) {
        TreeSet<Integer> tr1=new TreeSet<>();
        tr1.add(1);
        tr1.add(5);
        tr1.add(3);
        System.out.println(tr1);
        System.out.println("=====  =====  ====");
        TreeSet<String> tr2=new TreeSet<>();
        tr2.add("xyz");
        tr2.add("def");
        tr2.add("abc");
        System.out.println(tr2);
        System.out.println("=====  ===== =====");
        TreeSet<Xxx> tr3 = new TreeSet<>();
        tr3.add(new Xxx(3));
        tr3.add(new Xxx(1));
        tr3.add(new Xxx(5));
        System.out.println(tr3);
        System.out.println("=== === ===");

        // all such elements must be mutually comparable: e1.compareTo(e2) ...
        //   must not throw a ClassCastException for any elements e1 and e2 in the set.
        // 简单理解：必须是同一种类型
        // java.lang.ClassCastException
//        TreeSet<Object> ts4 = new TreeSet<>();
//        ts4.add(1);
//        ts4.add("string");
//        System.out.println(ts4);
    }
}
